from django.db import models

# Create your models here.
from django.db import models


class TDept(models.Model):
    dept_id = models.AutoField(primary_key=True)
    dept_name = models.CharField(max_length=200, blank=True, null=True)
    dept_loc = models.CharField(max_length=200, blank=True, null=True)

    class Meta:
        db_table = 't_dept'


class TFunction(models.Model):
    function_id = models.AutoField(primary_key=True)
    function_father = models.ForeignKey('self', models.DO_NOTHING, blank=True, null=True)
    function_name = models.CharField(max_length=200, blank=True, null=True)
    function_url = models.CharField(max_length=200, blank=True, null=True)
    function_show = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        db_table = 't_function'


class TIdcard(models.Model):
    idcard_id = models.AutoField(primary_key=True)
    idcard_num = models.CharField(max_length=18, blank=True, null=True)

    class Meta:
        db_table = 't_idcard'


class TRole(models.Model):
    role_id = models.AutoField(primary_key=True)
    role_name = models.CharField(max_length=200, blank=True, null=True)

    class Meta:
        db_table = 't_role'


class TRoleFunction(models.Model):
    role = models.ForeignKey(TRole, models.DO_NOTHING, blank=True, null=True)
    function = models.ForeignKey(TFunction, models.DO_NOTHING, blank=True, null=True)

    class Meta:
        db_table = 't_role_function'


class TUser(models.Model):
    user_id = models.AutoField(primary_key=True)
    idcard = models.ForeignKey(TIdcard, models.DO_NOTHING,null=True)
    dept = models.ForeignKey(TDept, models.DO_NOTHING, null=True)
    user_name = models.CharField(max_length=200, null=True)
    user_password = models.CharField(max_length=200,null=True)

    class Meta:
        db_table = 't_user'


class TUserRole(models.Model):
    user = models.ForeignKey(TUser, models.DO_NOTHING, blank=True, null=True)
    role = models.ForeignKey(TRole, models.DO_NOTHING, blank=True, null=True)

    class Meta:
        db_table = 't_user_role'
